<?php

class ServiceResult {
	/**
	 * the result message, error message if failed
	 * @var String
	 */
	private $message;
	/**
	 * the code for the message
	 * @var String
	 */
	private $code;
	/**
	 * whether the service success or failed
	 * @var boolean
	 */
	private $result;
	
	public function __construct(){
		$this->result = true;
	}
	
	public function setFailed($code, $message) {
		$this->code = $code;
		$this->message = $message;
		$this->result = false;
	}
	
	public function setException($e) {
		$this->setFailed($e->getCode(), $e->getMessage());
	}
	
	public function setSuccess() {
		$this->result = true;
	}
	
	public function isSuccess() {
		return $this->result;
	}
	
	public function isFailed() {
		return !($this->result);
	}
	
	public function getCode() {
		return $this->code;
	}
	
	public function getMessage() {
		return $this->message;
	}
}

?>